import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenTwoRouter } from '../Common/options'
import { OrganizationIdentityLevel } from '../Common/Conversion'

export const PlanStat = async ({ url, OptionsEvent, Permission, actionRef }) => {
    const OrgList = await OrganizationIdentityLevel(3)
    const planOrStatList = { 3: '总体计划', 2: '年计划', 0: '月计划', 1: '月统计' }
    let data = {
        pageSize: 10,
        params: { pageIndex: 1, OrderField: 'createTime@desc' },
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission.findIndex(v => v.uuid === 'f0eb4acd-5eb6-4ddc-af41-77a1e25ebb65') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'tableName',
                title: '名称',
                valueType: 'input',
                hideInAdded: true,
                hideInSearch: true,
                hideInModify: true,
                render: (_, { organizationUuid, yearMonth, planOrStat }) => {
                    return (
                        <div>
                            {OrgList[organizationUuid]}
                            {planOrStatList[planOrStat]}
                            {yearMonth}
                        </div>
                    )
                },
                width: 400,
            },
            {
                dataIndex: 'organizationUuid',
                title: '组织机构',
                valueType: 'select',
                valueEnum: OrgList,
                ellipsis: true,
                width: 300,
                rules: true,
            },
            {
                dataIndex: 'yearMonth',
                title: '年月',
                valueType: 'Date',
                picker: 'month',
                hideInSearch: true,
                showDate: true,
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'planOrStat',
                title: '类型',
                valueType: 'select',
                valueEnum: planOrStatList,
                ellipsis: true,
                width: 100,
                rules: true,
            },
            commonTableList.remark,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === 'aab9b58b-5acc-492f-afe9-4b2660bef9bb') !== -1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        <OpenTwoRouter
                            key="TwoTwo"
                            title="附件"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'PlanStatAttachment',
                                Permission,
                                actionRef,
                                oneData: record,
                                header: data.columns,
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === '86c2f612-8bb4-4e42-90e3-e35766c57612') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
